package com.bxait.toymail.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import com.bxait.toymail.product.vo.SearchResultProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.product.entity.SkuInfoEntity;
import com.bxait.toymail.product.service.SkuInfoService;

import javax.naming.directory.SearchResult;


/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * sku信息
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:26:35
 */
@RestController
@RequestMapping("product/skuInfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;


    @GetMapping("/SaleAttrValues/{skuId}")
    R getSkuSaleAttrValues(@PathVariable("skuId") Long skuId){
        List<String> list = skuInfoService.getSkuSaleAttrValues(skuId);
        return R.ok().setData(list);
    }

    @GetMapping("/search")
    public R search(){
        SearchResultProduct result = skuInfoService.search();
        return R.ok().setData(result);
    }

    /**
     * @param params
     * @==============History===============<br/>
     * @Description // TODO  获取sku列表
     * @Date 2023/3/21 19:56
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageByCondition(params);

        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("data", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }


    /*
     * @param skuId
     * @==============History===============<br/>
     * @Description //   获取当前sku商品的价格
     * @Date 2023/4/30 2023/4/30
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return com.bxait.com.utils.R
     */
    @GetMapping("/{skuId}/price")
    public R getPrice(@PathVariable("skuId") Long skuId){
        SkuInfoEntity entity = skuInfoService.getById(skuId);
        return R.ok().setData(entity.getPrice().toString());
    }




}
